package com.hjw.controller.adm.echarts;

import cn.dev33.satoken.util.SaResult;
import com.hjw.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @创建时间：2025-04-28
 * @文件名称：satoken_sobuk - com.hjw.controller.adm.echarts
 */
@Slf4j
@RestController
@RequestMapping("/api/adm/echarts")
public class AdmEchartsController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/getNum")
    public SaResult get() {
        LocalDate now = LocalDate.now();
        int monthValue = now.getMonthValue();
        int year = now.getYear();
        Map<String, Object> map = new HashMap<>(2);
        List<String> days = new ArrayList<>(4);
        List<Double> nums = new ArrayList<>(4);
        for (int i = monthValue,j=0; j < 6 ; j++) {
            if (i == 0){
                i = 12;
                year--;
            }
            days.add(year+"-"+i);
            System.out.println(year+"-"+i);
            Double mouth = orderService.findByMouth(year, i);
            nums.add(mouth == null ? 0 : mouth);
            i--;
        }
        map.put("days", days);
        map.put("nums", nums);
        return SaResult.get(200, "获取成功", map);
    }

    @GetMapping("/getMoney")
    public SaResult getMoney() {
        LocalDate now = LocalDate.now();
        int monthValue = now.getMonthValue();
        int year = now.getYear();
        Map<String, Object> map = new HashMap<>(2);
        List<String> days = new ArrayList<>(6);
        List<Double> amount = new ArrayList<>(6);
        for (int i = monthValue,j=0; j < 6 ; j++) {
            if (i == 0){
                i = 12;
                year--;
            }
            days.add(year+"-"+i);
            Double mouth = orderService.findByMouthMoney(year, i);
            amount.add(mouth == null ? 0 : mouth);
            i--;
        }
        map.put("days", days);
        map.put("amounts", amount);
        return SaResult.get(200, "获取成功", map);
    }

    @GetMapping("/getStatus")
    public SaResult getStatus() {
        Map<String, Object> map = new HashMap<>(2);
        map.put("payStatus", orderService.getPayStatusCount(1));
        map.put("shipStatus", orderService.getShipStatusCount(0));
        return SaResult.get(200, "获取成功", map);
    }


}
